package com.example.demo.config.Persistence;

import com.example.demo.app.entity.FormEntity;
import com.example.demo.app.entity.OrderEntity;
import com.example.demo.config.Persistence.persist.ComplexFormStateMachinePersist;
import com.example.demo.config.Persistence.persist.OrderStateMachinePersist;
import com.example.demo.config.enum_.ComplexFormEvents;
import com.example.demo.config.enum_.ComplexFormStates;
import com.example.demo.config.enum_.OrderEvents;
import com.example.demo.config.enum_.OrderStates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.persist.DefaultStateMachinePersister;
import org.springframework.statemachine.persist.StateMachinePersister;

/**
 * 状态机持久化Bean
 */
@Configuration
public class PersistConfig {
	/**
	 * 订单持久化BeanName
	 */
	public static final String orderPersister = "orderPersister";
	/**
	 * 简单表单持久化BeanName
	 */
    public  static final String  formPersister = "formPersister";

    
	@Autowired
    private OrderStateMachinePersist orderStateMachinePersist;

	@Autowired
	private ComplexFormStateMachinePersist complexFormStateMachinePersist;

	@Bean(name=orderPersister)
    public StateMachinePersister<OrderStates, OrderEvents, OrderEntity> orderPersister() {
		return new DefaultStateMachinePersister<OrderStates, OrderEvents, OrderEntity>(orderStateMachinePersist);
	}
	@Bean(name=formPersister)
	public StateMachinePersister<ComplexFormStates, ComplexFormEvents, FormEntity> formPersister() {
		return new DefaultStateMachinePersister<ComplexFormStates, ComplexFormEvents, FormEntity>(complexFormStateMachinePersist);
	}
}

